fix: start package manager before repo loading in peer mode#1687
Conversation
There was a problem hiding this comment.
Code Review
This pull request moves the startup logic of the ll-package-manager process in --no-dbus mode from Cli::getPkgMan() to main.cpp before the repository is loaded. The review feedback highlights that because of this relocation, the root user check (getuid() != 0) is executed too late. It is recommended to perform this check in main.cpp before spawning the process, and to verify the return value of QProcess::startDetached to ensure the process starts successfully.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
1. Move the ll-package-manager --no-dbus startup logic from Cli::getPkgMan() to main.cpp 2. Start the package manager immediately after detecting peer mode (--no-dbus flag) 3. Ensure the package manager is initialized before OSTreeRepo::loadFromPath() is called 4. The previous location in getPkgMan() was too late in the execution flow, as the repo was already loaded before the package manager had a chance to initialize Influence: 1. Test ll-cli with --no-dbus flag to verify package manager starts correctly 2. Verify that repository loading succeeds in peer mode 3. Test that subcommands work properly after the package manager initializes 4. Verify the 1-second sleep is sufficient for package manager startup 5. Test running ll-cli commands in --no-dbus mode multiple times to ensure no duplicate processes 6. Verify sudo permissions and environment variable preservation work correctly
5d14984 to
e0c65aa
Compare
deepin pr auto review★ 总体评分:35分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // apps/ll-cli/src/main.cpp
const bool peerMode = noDBusFlag->count() > 0;
if (peerMode) {
if (getuid() != 0) {
LogE("--no-dbus should only be used by root user.");
return -1;
}
// Start ll-package-manager --no-dbus first to initialize the repository
QProcess::startDetached("sudo",
{ "--user",
LINGLONG_USERNAME,
"--preserve-env=QT_FORCE_STDERR_LOGGING",
"--preserve-env=QDBUS_DEBUG",
LINGLONG_LIBEXEC_DIR "/ll-package-manager",
"--no-dbus" });
// Secure polling mechanism to wait for service readiness
const QString secureSocketPath = "/run/linglong/linglong-package-manager.socket";
constexpr int maxRetries = 20;
constexpr int retryIntervalMs = 100;
for (int i = 0; i < maxRetries; ++i) {
QFileInfo fileInfo(secureSocketPath);
// Verify socket exists and is owned by root to prevent TOCTOU attacks
if (fileInfo.exists() && fileInfo.ownerId() == 0) {
break;
}
QThread::msleep(retryIntervalMs);
}
}
auto repo = linglong::repo::OSTreeRepo::loadFromPath(LINGLONG_ROOT);// libs/linglong/src/linglong/cli/cli.cpp
if (this->peerMode) {
LogW("some subcommands will failed in --no-dbus mode.");
// Use Linux abstract namespace to prevent symlink hijacking in /tmp
const auto pkgManAddress = QString("unix:abstract=/linglong-package-manager");
const auto &pkgManConn =
QDBusConnection::connectToPeer(pkgManAddress, "ll-package-manager"); |
|
@dengbo11: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengbo11, reddevillg The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Influence: